#include <stdlib.h>
#include <stdio.h>
#define size 100
typedef int ElemType;
typedef struct {
    int i, j;
    int v;
}Triple;

typedef struct {
    Triple data[size];
    int m, n;
    int nonzeroCount;
}Matrix;

void createRandom(Matrix &A){
    A.m = 6 + rand() % 3;
    A.n = 8 + rand() % 3;
    A.nonzeroCount = 6 + rand() % 3;
    //输入
    int i, j, v;
    int cur = 0;
    printf("i < %d,j < %d,v任意整数\n", A.m, A.n);
    printf("空格隔开，输入%d个三元组:\n", A.nonzeroCount);
    for(int k = 0; k < A.nonzeroCount; k++){
        printf("第%d个:", k + 1);
        scanf("%d %d %d", &i, &j, &v);
        Triple triple;
        triple.i = i;
        triple.j = j;
        triple.v = v;
        A.data[cur++] = triple;
    }
}

void transpose(Matrix A, Matrix &B){
    B.m = A.n;
    B.n = A.m;
    B.nonzeroCount = A.nonzeroCount;
    int cur = 0;
    for(int col = 0; col < A.n; col++){
        for(int k = 0; k < A.nonzeroCount; k++){
            if(A.data[k].j == col){
                B.data[cur].i = A.data[k].j;
                B.data[cur].j = A.data[k].i;
                B.data[cur].v = A.data[k].v;
                cur++;
            }
        }
    }
}

void printMatix(Matrix matrix){
    int cur = 0;
    for(int i = 0; i < matrix.m; i++){
        for(int j = 0; j < matrix.n; j++){
            if(cur < matrix.nonzeroCount && matrix.data[cur].i == i && matrix.data[cur].j == j){
                printf("%d\t", matrix.data[cur++].v);
            }else{
                printf("%d\t", 0);
            }
        }
        printf("\n");
    }
}